#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "ui_mainwindow.h"
#include <QMainWindow>
#include <QTimer>
#include <QColor>
#include "QCustomPlot/qcustomplot.h"
#include "physics.h"
#include <sstream>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void setupForcesGraphs(QCustomPlot *plot);
    void setupMovementGraphs(QCustomPlot *plot);
    void setupTrajectoryGraph(QCustomPlot *plot);

private slots:
    void on_actionExit_triggered();
    void dataSlot();
    void x0change();

    void updateMassFromSlider();
    void updateMass();
    void updateSpringFactorFromSlider();
    void updateSpringFactor();
    void updateDampingFactorFromSlider();
    void updateDampingFactor();

    double updateParameterFromSlider(QSlider *slider, QLineEdit *lineEdit, double multiplier);
    double updateParameterFromTextBox(QLineEdit *lineEdit, QSlider *destSlider, double divisor);

    const char* doubleToConstChar(double val);
    double ConstCharToDouble(const char *s);

    void updatehOption();
    void updatehA();
    void updatehOmega();
    void updatehFi();

    void updatewOption();
    void updatewA();
    void updatewOmega();
    void updatewFi();

    void updateX0();
    void updateV0();
    void updateDelta();

    void restartSimulation();

    void on_actionStartSimulation_triggered();

    void on_actionPauseSimulation_triggered();

    void on_actionStopSimulation_triggered();

    void task5();

    void on_actionTask5_triggered();

private:
    Ui::MainWindow *ui;
    QTimer dataTimer;
    Physics *physics;
    double t;
    QCPCurve *trajectoryPlot;
    double maxForceY, minForceY;
    double maxMovementY, minMovementY;
    double maxTrajectoryX, minTrajectoryX, maxTrajectoryY, minTrajectoryY;

    QColor color[6] = {Qt::blue, Qt::red, Qt::green, Qt::gray, Qt::magenta, Qt::cyan };
    const char* movementGraphsNames[6] = {"x(t)", "v(t)", "a(t)", "w(t)", "x(t)-xe(t)", "|w(t)-x(t)|"};
    const char* forcesGraphsNames[3] = {"f(t)", "g(t)", "h(t)"};
    const char* trajectoryGraphNames = "trajectory";

    bool task5Flag = false;
    double q;
    double qx;
    double A;

signals:
    void found();
};

#endif // MAINWINDOW_H
